<html>
<head>
<title>管理系统</title>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<#include "../inc/commonJs.html">
<script type="text/JavaScript">
var logId = "", grid;
var fromuser = "${obj.userid!}";
	$(function() {
		//分类管理表格  
		grid = $('#taskLoggrid').datagrid({
        url:'listTaskLog.do',  
        loadMsg:'数据加载中请稍后……',  
        pagination: true,  
        rownumbers: true, 
        striped: true,  
        singleSelect : true,  
        pageSize: [${syscfg.pageSize!10}],
        pageList: [${syscfg.pageList!10}],
        queryParams: {
			taskid: '${obj.taskid!}'
		},
        columns:[[  
             {field:'logid',title: 'ID',align: 'center',width: '50'},  
             {field:'name',title: '日志名称',align: 'center',width: '250'},
             {field:'userName',title: '当前操作人',align: 'center',width: '100'},
             {field:'fromUserName',title: '上级操作人',align: 'center',width: '100'},
             {field:'dt',title: '时间',align: 'center',width: '200'},
             {field:'zt',title: '状态',align: 'center',width: '100',
             	formatter: function(value,rowdata,index){
             		var str = '<select id="zt_'+index+'" class="easyui-combobox" value='+value+' onchange="changeState(this,'+index+')" style="width:80px;" panelHeight="100px">'
             		if(value == 0){
             			str	+= '<option value="0" selected="true">待接收</option>'
             		}else{
             			str	+= '<option value="0" >待接收</option>'
             		}
             		if(value == 1){
             			str	+= '<option value="1" selected="true">进行中</option>'
             		}else{
             			str	+= '<option value="1" >进行中</option>'
             		}
             		if(value == 2){
             			str	+= '<option value="2" selected="true">完成</option>'
             		}else{
             			str	+= '<option value="2" >完成</option>'
             		}
             		str +='</select>'
					return str;
				}
             },
             //{field:'demo',title: '说明',align: 'center',width: '200'}
        ]],
        toolbar : [btn_del],
		onDblClickCell :function(index,field,value){
			var rowData = $('#taskLoggrid').datagrid('getData').rows[index];
			$('#taskzt').combobox('setValue', rowData.zt);
			$('#name').val(rowData.name);
			$('#userid').combobox('setValue', rowData.userid);
			$('#demo').val(rowData.demo);
			logId = rowData.logid;
		} 

    });
});
	//
	function changeState(_obj,_index){
		var worker = $('#taskLoggrid').datagrid('getData').rows[_index].userid;
		var logid = $('#taskLoggrid').datagrid('getData').rows[_index].logid;
		if(worker != ${userInfo.userid!}){
			window.top.$.messager.alert('提示',"你不是该任务日志操作人，无权限修改状态！");
			$('#zt_'+_index).val($('#taskLoggrid').datagrid('getData').rows[_index].zt);
			return;
		}
		$.post("${request.contextPath}/xadmin/work/updateTaskLogState.do", { "result": "zt="+$(_obj).val(),"logid":logid},
		   function(data){
		   	$('#taskLoggrid').datagrid('reload'); 
		   	window.top.$.messager.alert('提示',data);
		});
	}
	function addTaskLog() {
		var worker = $('#userid').combobox('getValue');
		var url = "";
		if(logId){
			if(worker != ${userInfo.userid}){
				top.messageralert("你不是该任务日志操作人，无修改权限！");
				return;
			}
			url = '${request.contextPath}/xadmin/work/editTaskLog.do?logid='+logId;
		}else{
			url = '${request.contextPath}/xadmin/work/addTaskLog.do';
		}
		$('form').form('submit',{  
		    url:url,
		    onSubmit:function(param){
		    	param.fromuser = fromuser;
		    	param.taskid = '${obj.taskid!}';
				return $(this).form('validate')
		    },  
		    success:function(data){ 
				$('#taskLoggrid').datagrid('reload');
				window.top.$.messager.alert('提示',data);
				$('form').form('reset');
		    }  
		});
	};
	
	//删除分类管理
	function doDel(){
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		var worker = selected.userid;
		if(worker != '${userInfo.userid}'){
			top.messageralert("你不是该任务日志操作人，无删除权限！");
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("delTaskLog.do", { "tasklogid": selected.logid},
				   function(data){
				   	grid.datagrid('reload'); 
				   	top.messagershow(data);
				});
			}
		});
	}
	function resetForm(){
		logId = "";
		$('form').form('reset');
	}
</script>

</head>
<body class="easyui-layout">
	<div data-options="region:'center',split:true">
		<table id="taskLoggrid" data-options="fit:true,border:false"></table>
	</div>   
    <div data-options="region:'east',title:'日志操作',split:true" style="width:300px;">
    	<div style="text-align:center;">
    	<form method="post" name="taskLogForm" id="taskLogForm">
    		<table style="border:1px;margin:auto;">
			 <tr>
			 	<td>名称：</td>
			 	<td>
			 		<input class="easyui-validatebox" type="text" required="true" id="name" name="name" maxlength="30" style="width:200px;" >
			 	</td>
			 </tr>
			 <tr>
			 	<td>状态：</td>
			 	<td>
			 		<select id="taskzt" class="easyui-combobox" name="zt" style="width:200px;" panelHeight="100px">   
					    <option value="0">转办</option>
					    <option value="1">进行中</option>   
					    <option value="2">完成</option>   
					</select>
			 	</td>
			 </tr>
			 <tr>
			 	<td>操作人：</td>
			 	<td>
			 		<input id="userid" class="easyui-combobox" name="userid"  style="width:200px;" panelHeight:"auto" data-options="panelHeight:110,valueField:'userid',textField:'username',url:'${request.contextPath}/xadmin/system/listUserForCombox.do'" />
			 	</td>
			 </tr>
			 <tr>
			 	<td>说明：</td>
			 	<td>
			 		<textarea rows="10" id="demo" name="demo" style="width:200px;"></textarea>
			 	</td>
			 </tr>
			 <tr id="saveBtn">
			 	<td colspan="2" align="center">
			 		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="addTaskLog();">保存</a>  
			 		<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="resetForm();">重置</a>
			 	</td>
			 </tr>
			</table>
		</form>
    	</div>
    </div>  
</body>
</html>